﻿<UserControl
    x:Class="MvvmFx.Samples.HowTos.ViewModelHelper.Views.ViewModelHelperView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mvvm="clr-namespace:MvvmFx.Common.ViewModels;assembly=MvvmFx.Common"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:converters="clr-namespace:MvvmFx.Common.Converters;assembly=MvvmFx.Common"
    xmlns:views="clr-namespace:MvvmFx.Samples.HowTos.ViewModelHelper.Views">

    <!-- resources -->
    <UserControl.Resources>
        
        <!-- converters -->
        <converters:ColorToSolidColorBrushConverter
            x:Key="converters.colorToSolidColorBrush" />

        <!-- data templates -->
        <DataTemplate
            x:Key="dataTemplates.headerTemplate">
            <TextBlock
                Text="{Binding Path=Title}" />
        </DataTemplate>

        <mvvm:HeaderedDataTemplate
            x:Key="viewModels.TabControlSample"
            Type="MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels.TabControlSampleViewModel"
            HeaderTemplate="{StaticResource dataTemplates.headerTemplate}">
            <Grid>
                <TextBlock
                    Text="Please read description above." />
            </Grid>
        </mvvm:HeaderedDataTemplate>

        <mvvm:HeaderedDataTemplate
            x:Key="viewModels.ItemsControlSample"
            Type="MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels.ItemsControlSampleViewModel"
            HeaderTemplate="{StaticResource dataTemplates.headerTemplate}">
            <views:ItemsControlSampleView />
        </mvvm:HeaderedDataTemplate>

        <mvvm:HeaderedDataTemplate
            x:Key="viewModels.MasterDetailsSample"
            Type="MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels.MasterDetailsSampleViewModel"
            HeaderTemplate="{StaticResource dataTemplates.headerTemplate}">
            <views:MasterDetailsSampleView />
        </mvvm:HeaderedDataTemplate>

        <mvvm:DataTemplate
            x:Key="viewModels.SampleItem"
            Type="MvvmFx.Samples.HowTos.ViewModelHelper.ViewModels.SampleItemViewModel">            
            <Grid Margin="5"> 
                
                <!-- row/column definitions -->
                <Grid.RowDefinitions>
                    <RowDefinition
                        Height="Auto" />
                    <RowDefinition
                        Height="Auto" />
                    <RowDefinition
                        Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition
                        Width="Auto" />
                    <ColumnDefinition
                        Width="*" />
                </Grid.ColumnDefinitions>

                <!-- name -->
                <TextBlock
                    Text="Name:"
                    FontWeight="Bold"
                    HorizontalAlignment="Right"
                    Margin="0, 0, 3, 0"
                    Grid.Row="0"
                    Grid.Column="0" />
                <TextBlock
                    Text="{Binding Path=Name}"
                    Grid.Row="0"
                    Grid.Column="1" />

                <!-- age -->
                <TextBlock
                    Text="Age:"
                    FontWeight="Bold"
                    HorizontalAlignment="Right"
                    Margin="0, 0, 3, 0"
                    Grid.Row="1"
                    Grid.Column="0" />
                <TextBlock
                    Text="{Binding Path=Age}"
                    Grid.Row="1"
                    Grid.Column="1" />

                <!-- Color -->
                <TextBlock
                    Text="Color:"
                    FontWeight="Bold"
                    HorizontalAlignment="Right"
                    Margin="0, 0, 3, 0"
                    Grid.Row="2"
                    Grid.Column="0" />
                <Border
                    Background="{Binding Path=Color, 
                        Converter={StaticResource converters.colorToSolidColorBrush}}"
                    CornerRadius="3"
                    BorderBrush="Black"
                    BorderThickness="1"
                    MaxWidth="200"
                    Grid.Row="2"
                    Grid.Column="1">
                    <ContentControl
                        Foreground="White"
                        Padding="2"
                        Content="{Binding Path=Color}" />
                </Border>
            </Grid>
        </mvvm:DataTemplate>

    </UserControl.Resources>

    <!-- root container -->
    <Grid
        Margin="10">

        <!-- row/column definitions-->
        <Grid.RowDefinitions>
            <RowDefinition
                Height="100" />
            <RowDefinition
                Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition
                Width="*" />
        </Grid.ColumnDefinitions>

        <!-- blurb -->
        <Border
            Style="{StaticResource styles.textBlock.descriptionBorder}">
            <Grid>

                <Grid.RowDefinitions>
                    <RowDefinition
                        Height="Auto" />
                    <RowDefinition
                        Height="*" />
                </Grid.RowDefinitions>

                <TextBlock
                    Style="{StaticResource styles.textBlock.descriptionHeader}"
                    Text="Description" />
                <ScrollViewer
                    VerticalScrollBarVisibility="Auto"
                    BorderBrush="Transparent"                    
                    Grid.Row="1">
                    <StackPanel
                        MaxWidth="500">
                        <TextBlock
                            Style="{StaticResource styles.textBlock.description}"
                            Text="{Binding Path=Description}" />
                    </StackPanel>
                </ScrollViewer>
            </Grid>
        </Border>

        <!-- tabs -->
        <controls:TabControl
            Margin="0, 10, 0, 0"
            mvvm:ViewModelHelper.ItemsSource="{Binding Path=Samples}"
            mvvm:ViewModelHelper.SelectedValue="{Binding Path=SelectedSample,
                Mode=TwoWay}"
            Grid.Row="1" />

    </Grid>

</UserControl>
